const path = require('path')
const fs = require('fs')
const fse = require('fs-extra')

const getPathfromcwd = (relativePath) => path.join(process.cwd(), relativePath)
const copyPublicToDist = (publicPath, outputPath, templatePath) => {
    // 清空dist
    fse.emptyDirSync(outputPath)
    // 复制public目录，不包含Template.html
    fse.copySync(publicPath, outputPath, {
        filter: (fileName) => {
            return fileName !== templatePath
        }
    })
}
const writeJs = (contet, outputPath) => {
    const jsFolderPath = path.join(outputPath, './js')
    fse.emptyDirSync(jsFolderPath)
    const jsFileName = path.join(jsFolderPath, './index.js')
    fs.writeFileSync(jsFileName, contet, { encoding: 'utf-8' })
}
const isJsonByFilePath = (filePath) => /\.json$/.test(filePath)
const isJsByFilePath = (filePath) => /\.js$/.test(filePath)
const isCssByFilePath = (filePath) => /\.css$/.test(filePath)

module.exports = {
    getPathfromcwd,
    copyPublicToDist,
    writeJs,
    isJsonByFilePath,
    isJsByFilePath,
    isCssByFilePath
}